package com.yyplatform.admin.platform.role.controller;

import static com.yyplatform.admin.Constants.URL_PREFIX;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yyplatform.admin.infra.model.RestResponse;
import com.yyplatform.admin.platform.role.model.dto.SysPostDTO;
import com.yyplatform.admin.platform.role.model.dto.SysPostFormDTO;
import com.yyplatform.admin.platform.role.model.dto.SysPostQueryDTO;
import com.yyplatform.admin.platform.role.service.SysPostService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * Created on 2024-09-13
 */
@Slf4j
@Tag(name = "用户/岗位管理")
@AllArgsConstructor
@RestController
@RequestMapping(URL_PREFIX + "/sys/post/")
public class SysPostController {

    private SysPostService sysPostService;


    @GetMapping("query")
    @Operation(summary = "查询")
    @RequiresPermissions("sys:post:query")
    public RestResponse<Page<SysPostDTO>> page(SysPostQueryDTO pageQueryDTO) {
        log.debug("query dto = {}", pageQueryDTO);

        Page<SysPostDTO> page = sysPostService.query(pageQueryDTO);

        return RestResponse.ok(page);
    }


    @GetMapping("options")
    @Operation(summary = "获取下拉options")
    @RequiresPermissions("sys:post:options")
    public RestResponse<List<SysPostDTO>> options() {

        return RestResponse.ok(sysPostService.getOptions());
    }


    @GetMapping("get")
    @Operation(summary = "通过ID获取详情")
    @RequiresPermissions("sys:post:get")
    public RestResponse<SysPostDTO> get(Long id) {
        log.debug("get by id is {}", id);

        SysPostDTO data = sysPostService.get(id);
        return RestResponse.ok(data);
    }


    @PostMapping("save")
    @Operation(summary = "保存")
    @RequiresPermissions("sys:post:save")
    public RestResponse<Void> save(@RequestBody SysPostFormDTO sysDeptFormDTO) {
        log.debug("save dto is {}", sysDeptFormDTO);

        sysPostService.save(sysDeptFormDTO);

        return RestResponse.ok(null);
    }


    @PostMapping("update")
    @Operation(summary = "修改")
    @RequiresPermissions("sys:post:update")
    public RestResponse<Void> update(@RequestBody SysPostFormDTO sysDeptFormDTO) {
        log.debug("update dto is {}", sysDeptFormDTO);

        sysPostService.update(sysDeptFormDTO);
        return RestResponse.ok(null);
    }


    @PostMapping("delete")
    @Operation(summary = "删除")
    @RequiresPermissions("sys:post:delete")
    public RestResponse<Void> delete(Long id) {
        log.debug("delete by id is {}", id);

        sysPostService.delete(id);
        return RestResponse.ok(null);
    }


}
